﻿using AutoMapper;
using MediatR;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Domains.zjy;
using RearLivestock.Common.Dtos;
using RearLivestock.Common.Infrastructure.Interface;
using RearLivestock.RBAC.Api.Application.hqApplication.Commands.Bedroomss;
using RearLivestock.RBAC.ErrorCodeEnum;

namespace RearLivestock.RBAC.Api.Application.hqApplication.Commands.Ablactationss
{
    public class AddAblactationsHander : IRequestHandler<AddAblactationsCommand, Result>
    {
        /// <summary>
        /// 种母期初
        /// </summary>
        private readonly IBaseRepository<Ablactations> _ablactationsRepository;

        /// <summary>
        /// mapper
        /// </summary>
        private readonly IMapper _mapper;

        public AddAblactationsHander(IBaseRepository<Ablactations> ablactationsRepository, IMapper mapper)
        {
            _ablactationsRepository = ablactationsRepository;
            _mapper = mapper;
        }


        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(AddAblactationsCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Added };
           
           
            var res = _ablactationsRepository.AddRange(request.Ablactations);
            if (res > 0)
            {
                result.Code = (int)CommonErrorCode.Success;
                result.Msg = "添加断奶期初成功";
            }

            return result;
        }
    }
}
